package com.boot.demo.config.service;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;

@Configuration //说明是一个配置文件
@EnableTransactionManagement //开启事务管理
public class TransactionManagementConfiguration implements TransactionManagementConfigurer{
	//注入dataSource
	@Autowired
	private DataSource dataSource;

	@Override
	public TransactionManager annotationDrivenTransactionManager() {
		//返回的是dataSource
		return new DataSourceTransactionManager(dataSource);
	}
	
}
































//@Configuration  //说明配置文件
//@EnableTransactionManagement   //开启支持事务管理
//public class TransactionManagementConfiguration implements TransactionManagementConfigurer{
//
//	//注入dataSource
//	@Autowired
//	private DataSource dataSource;
//	
//	//需要返回dataSource
//	@Override
//	public TransactionManager annotationDrivenTransactionManager() {
//		return new DataSourceTransactionManager(dataSource);
//	}
//	
//}
